
def prime(uwu):
    I = True
    for sus in range(2, int(uwu ** 0.5)+1):
        if uwu % sus == 0:
            I = False
            break
        return I


g = int(input())
if g < 1000 or g > 9999:
    print(0)
else:
    T = str(g)
    t = 0
    for z in range(len(T)):
        for j in range(z+1, len(T)+1):
             num = int(T[z:j])
             if prime(num):
                 t = max(t, num)
    print(t)